
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>排期管理</title>
     <#include "../StaticFile.ftl">
    <script>
    
    

    var toolbar = [{
            text:'新增排期',
            iconCls:'icon-add',
            handler:function(){global.id=0;$('#dlg').dialog('open');clean();}
        }];
    
    </script>
</head>
<body>




<div id="cc" class="easyui-layout" style="width:100%;height:900px;">
     <#include "../Head.ftl">
     <#include "../Menu.ftl">
    <div data-options="region:'center',title:'数据显示区',split:true">
    
   
    <table id="dg" title="排期列表" style="width:100%" data-options="
                singleSelect:true,
                autoRowHeight:false,
                pagination:true,
                url:'/schedule/getdata?page_id=${page_id}',
                pageSize:20,toolbar:toolbar">
        <thead>
            <tr>
                <th field="id" width="80" align="center">排期编号</th>
                 <th data-options="field:'createdate',width:160,align:'center',formatter:formatDateTime" width="160">创建时间
                 </th>
                  <th data-options="field:'pageName',width:80,align:'center'" width="100">页面名称</th>
                <th data-options="field:'begintime',width:160,align:'center',formatter:formatDateTime">开始时间</th>
                <th data-options="field:'endtime',width:160,align:'center',formatter:formatDateTime">结束时间</th>
                <th data-options="field:'status',width:180,align:'center',formatter:formatStatus" >状态</th>
                <th data-options="field:'operation',width:160,align:'center',formatter:formatOperation" >操作</th>
            </tr>
        </thead>
    </table>
   
   
      <div id="dlg" class="easyui-dialog" title="创建排期" data-options="iconCls:'icon-save'" style="width:400px;height:250px;padding:10px;">
        
            <table cellpadding="5">
              
                <tr>
                    <td>开始时间:</td>
                    <td><input class="easyui-datetimebox" type="text" name="begintime" id="begintime" style="width:160px;" data-options="required:true,validType:'email'"></input></td>
                </tr>
                <tr>
                    <td>结束时间:</td>
                    <td><input class="easyui-datetimebox" type="text" name="endtime" id="endtime" data-options="required:true" style="width:160px;"></input></td>
                </tr>
            </table>
       
         <div style="text-align:center;padding:5px">
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="addElement()">添加</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">取消</a> 
         </div>
        </div>
       
      </div>
      </div>
     <script>
     function clearForm(){
            $('#dlg').dialog('close'); 
        }
          $(function(){
            var pager = $('#dg').datagrid().datagrid('getPager');
            $('#dlg').dialog('close');
            $('#dlg_add_content').dialog('close');
             })
               // get the pager of datagrid
               
         function doSearch(){
            $('#dg').datagrid('load',{
         
            });
            }
            var  global={id:0,page_id:${page_id}};
            function addElement()
            {
            
                var begintime=$("#begintime").textbox("getValue");
                var endtime=$("#endtime").textbox("getValue");
                if(!begintime){
                    alert("开始时间不能为空");
                    return;
                }
                if(!endtime){
                    alert("结束时间不能为空");
                    return;
                }
                if(begintime>endtime){
                    alert("结束时间不能小于开始时间");
                    return;
                }
                 if(!window.confirm("确定要保存么？"))
                {
                    return;
                }
                
                $.ajax({
                type: "POST",
                  url: "/schedule/add",
                  data:{
                  id:global.id,
                  begintime:begintime,
                  endtime:endtime,
                  page_id:global.page_id
                  },
                  success:function(data)
                  {
                    //var result=jQuery.parseJSON(data);
                    
                    doSearch();
                    $('#dlg').dialog('close');
                    
                  }
                  });
            }
            
            function clean()
            {
                
                  $("#begintime").textbox("setValue","");
                  $("#endtime").textbox("setValue","");
                 
                  
                   
            }
        function formatOperation(val,row)
        {
        
           
            if(row.status==0)
            {
                return '<a href="javascript:void(0)" class="easyui-linkbutton" style="padding-right:5px;" onclick="upadateStatus('+row.id+',1)">禁用</a>'
               + '<a href="javascript:void(0)" class="easyui-linkbutton" style="padding-right:5px;" onclick="editElement('+row.id+',1)">编辑</a><a href="javascript:void(0)" class="easyui-linkbutton"  onclick="targetContent('+row.id+')">内容块</a>'
            }
            else
            {
                return '<a href="javascript:void(0)" class="easyui-linkbutton"  style="padding-right:5px;" onclick="upadateStatus('+row.id+',0)">启用</a>'+
                '<a href="javascript:void(0)" class="easyui-linkbutton" style="padding-right:5px;" onclick="editElement('+row.id+',1)">编辑</a>'
                +'<a href="javascript:void(0)" class="easyui-linkbutton" onclick="targetContent('+row.id+')">内容块</a>'
               
            }
           
        }
        
         function upadateStatus(id,status)
            {
             if(!window.confirm("确定要修改么？"))
                {
                    return;
                }
                $.ajax({ type: "GET",
                url: "/schedule/changestatus?id="+id+"&status="+status+"&page_id="+global.page_id,
                success: function(data)
                 {
                    var returnData=jQuery.parseJSON(data);
                    if(returnData.code==0)
                    {
                        doSearch(); 
                    }
                    else
                    {
                        alert(returnData.msg);
                    }
                  }});
            }
            
        function editElement(id,status){
        
              global.id=id;
              $.ajax({ type: "GET",
                url: "/schedule/getelement?id="+id,
                success: function(data)
                 {
                    var returnData=jQuery.parseJSON(data);
                    if(returnData.code==0)
                    {
                     $('#dlg').dialog('open');
                     var element=returnData.data;
                     $("#begintime").textbox("setValue",formatTime(element.begintime));
                     $("#endtime").textbox("setValue",formatTime(element.endtime));
                    }
              
                  }});
        }
        
        function clean(){
        
               $("#beigintime").textbox("setValue","");
                     $("#endtime").textbox("setValue","");       
        }
        function formatStatus(val,row){
            var currentTime=new Date().getTime();
            var currentStatus="";
            if(row.begintime<=currentTime&&currentTime<=row.endtime)
            {
                currentStatus="排期中";
            }
            else if(currentTime>row.endtime)
            {
                 currentStatus="排期结束";
            }
            else
            {
                currentStatus="排期结束";
            }
            if(val==0)
            {
                return "正常("+currentStatus+")";
            }
            else
            {
                return "禁用("+currentStatus+")";
            }
        }
         function formatIcon(val,row)
        {
           return "<img style='high:30px;width:30px' src='"+val+"'/>";
        } 
        
        function targetContent(id)
        {
               window.location.href="/schedulecontent/list?schedule_id="+id+"&page_id="+global.page_id;
                  
        }
        
        function formatDateTime(val,row)
        {
            
             return formatTime(val);
        }
    </script>
    
</body>
</html>